[Gecko]
###################################################################################3
$Classic Controller Support [Vague Rant, crediar, annotated and modded]
###################################################################################3


## [SHAKING RE-MAPPING] ##
# Adds a check for button 0x80 (an unused button) to act as the "Shake" trigger 

# Light Cycle #
C2102D58 00000005  # Hook into Light Cycle shake handler at 0x80102D58; 5 instruction pairs extend behavior

41820020 801F0044  # If a prior condition fails, skip CC‑based shake logic ;; otherwise, read current button state word for this mode
70000080 40820014  # Mask button state with 0x80 (unused CC button) ;; if that bit is not set, skip CC‑triggered shake
3C008010 60002D70  # Prepare call target address for shake routine in Light Cycle code ;; combine high/low parts into full address
7C0903A6 4E800420  # Branch to the game’s original shake handler using the prepared address ;; return to this hook afterward
60000000 00000000  # No‑op / alignment after injected logic ;; terminator for this hook

# Light Disc #
C2172C38 00000005  # Hook into Light Disc shake handler at 0x80172C38; 5 instruction pairs extend behavior

41820020 801E0044  # If a prior condition fails, skip CC‑based shake logic ;; otherwise, read current button state word for this mode
70000080 40820014  # Mask button state with 0x80 (unused CC button) ;; if that bit is not set, skip CC‑triggered shake
3C008017 60002C40  # Prepare call target address for shake routine in Light Disc code ;; combine high/low parts into full address
7C0903A6 4E800420  # Branch to the game’s original shake handler using the prepared address ;; return to this hook afterward
60000000 00000000  # No‑op / alignment after injected logic ;; terminator for this hook

## Runner mode ##
C21F30B4 00000005  # Hook into Runner shake handler at 0x801F30B4; 5 instruction pairs extend behavior

41820020 801F0044  # If a prior condition fails, skip CC‑based shake logic ;; otherwise, read current button state word for this mode
70000080 40820014  # Mask button state with 0x80 (unused CC button) ;; if that bit is not set, skip CC‑triggered shake
3C00801F 600030C4  # Prepare call target address for shake routine in Runner code ;; combine high/low parts into full address
7C0903A6 4E800420  # Branch to the game’s original shake handler using the prepared address ;; return to this hook afterward
60000000 00000000  # No‑op / alignment after injected logic ;; terminator for this hook



# [MINI GAME ID TRACKER]
# Writes the current game mode address to 80002FFC. This acts as a master switch, allowing the code to know which minigame is active

C22D6C6C 00000002  # Hook at 0x802D6C6C; 2 instruction pairs add global game‑mode tracking

3CA08000 90C52FFC  # Load base address 0x80000000 and compute 0x80002FFC ;; store current game mode pointer/value into 0x80002FFC as a global “active mode” slot
3C03FC27 00000000  # Prepare a constant (part of a game ID table or tag) for later use by other hooks ;; padding / no further change in this function

# [MOTION PLUS DISABLE]
# Disables MotionPlus check, as it triggers separate library reads that conflict with these patches[cite: 31, 32, 33].

04367F50 3860FFFF  # Overwrite code at 0x80367F50 so that MotionPlus detection returns a “disabled/invalid” value ;; prevents MotionPlus‑specific library reads that conflict with CC patches




##########################################################################################################
# [ANALOG TO MOTION/DIGITAL]
##########################################################################################################
# Replaces stock accelerometer reads with custom logic to handle steering (sideways) # or serving/throwing (vertical). Maps tilt/shake to Left/Right stick axes

C23A6E90 000000C0 ###0	; hook point; read 192 pairs in this function

#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# CLASSIC CONTROLLER CHECK (2 pairs)
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# Classic Controller Check / if NOT, skip everything (run original readkpadacc() normally)
88130028 2C000002 #1	; read byte from KPAD struct offset 0x28 -eq controller type field; 
						# compare type against 2 -eq Classic Controller
408205EC 60000000 ###2	; if no, move forward (total(384)-5 eq) 379x4 bytes;; Skip 378 instructions to (Return #R1.2)

#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%2
# GAME ID ROUTING (12 pairs, 14 total)
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# Game ID Retrieval
3CA08000 80A52FFC #3 ; set r5 to 0x80000000 # set r5 to *(0x80002FFC) — the minigame ID pointer saved by the [MINI GAME ID] patch 
2C050000 41820008 #4 ; is the pointer null? # if null, skip the dereference (use 0 as the ID) 
80A50010 60000000 #5 ; set r5 to *(r5+0x10) — dereference to actual game mode ID; clear r10 register

# ------------------------------------------------------------------
# r10 Classification for Analog Function
#
# 0 = Default Vertical
# 1 = Light Discs
# 2 = Horizontal (Runner + Light Cycles)
# ------------------------------------------------------------------

38E00000 39400000 #6    ; initialize r7 as 0 and r10 as 0

# Light Cycle ID 1
3CC5FC27 2806A0C6 #7	; is game ID 0x03D9A0C6 (Cycle mode 1?
40820008 39400002 #8   ; if mismatch, skip instruction; set r10 to 2

# Light Cycle ID 2
3CC5FFDA 280642D1 #9	; is game ID 0x002642D1 (Cycle mode 2)?
40820008 39400002 #10   ; if mismatch, skip instruction; set r10 to 2

# Runner ID
3CC5FC37 2806C646 #11	; is game ID 0x03C9C646 (Runner)?
40820008 39400002 #12   ; if mismatch, skip instruction; set r10 to 2

# Light Discs
3CC5FFE0 28060595 #13    ; is game ID ?? (Discs)?
40820008 39400001 #14    ; if mismatch, skip instruction; set r10 to 1


#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%14
# Motion Mapping (10 pairs, 24 total)
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# --------------------------------------------------------------------------------------------------------
# Light Cycle / Runner Steering 
# --------------------------------------------------------------------------------------------------------

# Game ID check
2C0A0002 4082001C #15   ; Does r10 match 2? if no, skip to vertical (skip 6 instructions)

# [No lateral tilt]
C002CFE0 D0150010 #16	; Load constant; store as ACC.y

# [LS X to filt F/B (L/R rotated)]
C015006C FC000050 #17	; Load LS X; Negate
D0150014 60000000 #18	; #C015006C Store as ACC.z

# --------------------------------------------------------------------------------------------------------
# Hyperball 
# --------------------------------------------------------------------------------------------------------

# Game ID check
2C0A0000 4082002C #19   ; Does r10 match 0? if no, skip to analog (skip 10 instructions)

# [Hyper Ball angle / left-right tilt]
C0150074 FC000050 #20	; Read RX to f0; inverse value to negative to match motion direction
D015000C 60000000 #21	; Write RX to ACC.x; 

# [No lateral tilt]
FC000028 D0150010 #22 	; Clear f0; Write ACC.y to 0

# [Hyper Ball serve/throw / up-down tilt]
C0150078 EC0000F2 #23 	; Read RY to f0; scale to f7 (pre-existing)
D0150014 60000000 #24 	; Write RY to ACC.z

#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# ANALOG Mapping
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

#=========================================================================================================
# LS X+ [006C] -- PAIRS 17 -- HELD STATE: 0004
#=========================================================================================================

#----------------------------------------------------------------------------------------------------------
# Dynamic Button Selection (6 pairs, 24+6 > 30 TOTAL)
#----------------------------------------------------------------------------------------------------------

2C0A0002 4182008C #LXP101    ; Is cycle_runner? If no, skip entire section (skip 34 instructions)
39800000 60000000 #LXP102    ; Clear r12 
2C0A0000 4082000C #LXP103    ; Compare Game ID (r10) to 0 (default_vertical) ;; If not 0, skip next 
39800002 60000000 #LXP104    ; Inject button mask 0002 (D-Pad Right)
2C0A0001 4082000C #LXP105    ; Compare Game ID to 1 (discs) ;; If not 1, skip next
39800004 60000000 #LXP106    ; Inject button mask 0002 (D-Pad Down) 

#----------------------------------------------------------------------------------------------------------
# Load Analog value and assess threshold (2 pairs, 30+2 > 32 total)
#----------------------------------------------------------------------------------------------------------

C015006C C02D000C #LXP201	; Load RS Y (float into f0 from r21.0074)
						    # Load threshold (float into f1 from r13.000C)
FC000800 41800044 #LXP202	; Is RS Y+ below threshold?
						    # If yes, move forward 17x4 bytes (0044). 
					    	# Skip 16 instructions to ***Release Path***

#----------------------------------------------------------------------------------------------------------
# LX+ Press Path (Analog active) (8 pairs, 32+8 > 40 total)
#----------------------------------------------------------------------------------------------------------

# Add designated button to current input 
80150000 7C006378 #LXP301	; Load button input (32-bit word into r0 from r21.0000)
						    # Set the button tag in r0 to 1 (active)
90150000 60000000 #LXP302	; Write r0 back into r21.0000

# Next Check held-state @@@ 0004 @@@@ / If held, skip to ***Next Analog***
88150084 70000004 #LXP303	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
						    # Is held state @@@ 0004 @@@@ active? (return 0)  
40820058 60000000 #LXP304	; if active (0), move forward 22x4 bytes (0048). 
						    # Skip 21 instructions to ***Next Analog***

# Next flag as just-pressed button, then skip to ***Next Analog***
80150004 7C006378 #LXP305	; load just-pressed bitmask from r21.0004 into r0
						    # inject button into r0
90150004 60000000 #LXP306	; WRITE r0 into r21.0004 (just-pressed state) 

# Next flag held state @@@ 0004 @@@@, then skip to ***Next Analog***
88150084 60000004 #LXP307	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
						    # Set held state @@@ r0.0004 @@@@ to 1 (active)
98150084 48000034 #LXP308	; WRITE r0 into r21.0084 (held state)
						    # Move forward 13x4 bytes (0034). Skip 12 instructions to ***Next Analog***

#----------------------------------------------------------------------------------------------------------
# LX+ Release Path (Analog inactive) (6 pairs, 40+6 > 46 total)
#----------------------------------------------------------------------------------------------------------

# Check if held state @@@ 0004 @@@@ is active / If not, skip to ***Next Analog***
88150084 70000004 #LXP401	; load held-state bitmask from r21.0084 into r0 
						    # Is held state @@@ 0004 @@@@ active? (return 0) 
41820028 60000000 #LXP402	; if inactive (1), Move forward 10x4 bytes (0028). 
						    # Skip 9 instructions to ***Next Analog***

# Next flag as just-released button
80150008 7C006378 #LXP403	; load just-released bitmask from r21.0008 
						    # inject button into r0
90150008 60000000 #LXP404	; WRITE r0 into r21.0008 (just-released state)  

# Next clear held flag for held state @@@ 0004 @@@@
88150084 39800004 #LXP405	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
						    # load into r12 held state @@@ 0004 @@@@
7C006078 98150084 #LXP406	; Invert r12, and write that button into r0
						    # WRITE r0 into r21.0084 (held state)


#=========================================================================================================
# LS X- [006C] -- PAIRS 18 -- BUTTON: DPAD UP (LEFT) -- BUTTON MASK: 0002 -- HELD STATE: 0008
#=========================================================================================================

#----------------------------------------------------------------------------------------------------------
# Dynamic Button Selection (6 pairs, 46+6 > 52 TOTAL)
#----------------------------------------------------------------------------------------------------------

2C0A0002 4182008C #LXM101   ; Is cycle_runner? If no, skip entire section (skip 34 instructions)
39800000 60000000 #LXM102   ; Clear r12 
2C0A0000 4082000C #LXM103   ; Compare Game ID (r10) to 0 (default_vertical) ;; If not 0, skip next 
39800001 60000000 #LXM104   ; Inject button mask 0001 (D-Pad Left)
2C0A0001 4082000C #LXM105   ; Compare Game ID to 1 (discs) ;; If not 1, skip next
39800008 60000000 #LXM106   ; Inject button mask 0002 (D-Pad Up) 

#----------------------------------------------------------------------------------------------------------
# Load Analog value and assess threshold (3 pairs, 52+3 > 55 total)
#----------------------------------------------------------------------------------------------------------

C015006C FC000050 #LXM201	; Load RS Y (float into f0 from r21.0074)
						    # inverse value from negative to positive (negative value now accepted and positive rejected)
C02D000C FC000800 #LXM202	; Load threshold (float into f1 from r13.000C)
						    # Is RS Y below threshold?
41800048 60000000 #LXM203	; If yes, move forward 18x4 bytes (0048). 
						    # Skip 17 instructions to #32.1 (RX- release)

#----------------------------------------------------------------------------------------------------------
# LX- Press Path (Analog active) (8 pairs, 55+8 > 63 total)
#----------------------------------------------------------------------------------------------------------

# Add designated button to current input 
80150000 7C006378 #LXM301	; Load button input (32-bit word into r0 from r21.0000)
						    # Set the button tag %%% 0002 %%% in r0 to 1 (active)
90150000 60000000 #LXM302	; Write r0 back into r21.0000

# Next Check held-state @@@ 0008 @@@@ / If held, skip to ***Next Analog***
88150084 70000008 #LXM303	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
						    # Is held state @@@ 0008 @@@@ active? (return 0)  
40820058 60000000 #LXM304	; if active (0), move forward 22x4 bytes (0048). 
						    # Skip 21 instructions to ***Next Analog***

# Next flag as just-pressed button, then skip to ***Next Analog***
80150004 7C006378 #LXM305	; load just-pressed bitmask from r21.0004 into r0
						    # inject button %%% 0002 %%% into r0 
90150004 60000000 #LXM306	; WRITE r0 into r21.0004 (just-pressed state) 

# Next flag held state @@@ 0008 @@@@, then skip to ***Next Analog***
88150084 60000008 #LXM307	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
						    # Set held state @@@ r0.0008 @@@ to 1 (active)
98150084 48000034 #LXM308	; WRITE r0 into r21.0084 (held state)
						    # Move forward 13x4 bytes (0034). Skip 12 instructions to ***Next Analog***

#----------------------------------------------------------------------------------------------------------
# LX- Release Path (Analog inactive) (6 pairs, 63+6 > 69 total)
#----------------------------------------------------------------------------------------------------------

# Check if held state @@@ 0008 @@@@ is active / If not, skip to ***Next Analog***
88150084 70000008 #LXM401	; load held-state bitmask from r21.0084 into r0 
						    # Is held state @@@ 0008 @@@@ active? (return 0) 
41820028 60000000 #LXM402	; if inactive (1), Move forward 10x4 bytes (0028). 
						    # Skip 9 instructions to *Next Analog*

# Next flag as just-released button
80150008 7C006378 #LXM403	; load just-released bitmask from r21.0008 
						    # inject button into r0 %%% 0002 %%%
90150008 60000000 #LXM404	; WRITE r0 into r21.0008 (just-released state)  

# Next clear held flag for held state @@@ 0008 @@@@
88150084 39800008 #LXM405	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
						    # load into r12 held state @@@ 0008 @@@@
7C006078 98150084 #LXM406	; Invert r12, and write that button into r0
						    # WRITE r0 into r21.0084 (held state)

#=========================================================================================================
# LS Y+ [0070] -- PAIRS 16 -- BUTTON: UNUSED1 -- BUTTON MASK: 0020 -- HELD STATE: 0001
#=========================================================================================================

#----------------------------------------------------------------------------------------------------------
# Dynamic Button Selection (7 pairs, 69+7 > 76 TOTAL)
#----------------------------------------------------------------------------------------------------------

39800000 60000000 # LYP101 ; Clear r12 
2C0A0000 4082000C # LYP102 ; Compare Game ID (r10) to 0 (default_vertical) ;; If not 0, skip next 
39800008 60000000 # LYP103 ; Inject button mask 0008 (D-Pad Up)
2C0A0001 4082000C # LYP104 ; Compare Game ID to 1 (discs) ;; If not 1, skip next
39800002 60000000 # LYP105 ; Inject button mask 0002 (D-Pad Right) 
2C0A0002 4082000C # LYP106 ; Compare Game ID to 2 (cycle_runner) ;; If not 2, skip next 
39800020 60000000 # LYP107 ; Inject button mask 0020 (UNUSED1)

#----------------------------------------------------------------------------------------------------------
# Load Analog value and assess threshold (2 pairs, 76+2 > 78 total)
#----------------------------------------------------------------------------------------------------------

C0150070 C02D000C #LYP201	; Load LS Y (float into f0 from r21.0070)
					    	# Load threshold (float into f1 from r13.000C)
FC000800 41800044 #LYP202	; Is LS Y below threshold?
					    	# If yes, move forward 17x4 bytes (0044). 
				      		# Skip 16 instructions to ***Release Path***

#----------------------------------------------------------------------------------------------------------
# LY+ Press Path (Analog active) (8 PAIRS, 78+8 > 86 TOTAL)
#----------------------------------------------------------------------------------------------------------

# Add designated button to current input 
80150000 7C006378 #LYP301	; Load button input (32-bit word into r0 from r21.0000)
				    		# Set the button tag %%% 0020 %%% in r0 to 1 (active)
90150000 60000000 #LYP302	; Write r0 back into r21.0000

# Next Check held-state @@@ 0001 @@@@ / If held, skip to ***Next Analog***
88150084 70000001 #LYP303	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
					    	# Is held state @@@ 0001 @@@@ active? (return 0)  
40820058 60000000 #LYP304	; if active (0), move forward 22x4 bytes (0048). 
					    	# Skip 21 instructions to ***Next Analog***

# Next flag as just-pressed button, then skip to ***Next Analog***
80150004 7C006378 #LYP305	; load just-pressed bitmask from r21.0004 into r0
					    	# inject button %%% 0020 %%% into r0
90150004 60000000 #LYP306	; WRITE r0 into r21.0004 (just-pressed state) 

# Next flag held state @@@ 0001 @@@@, then skip to ***Next Analog***
88150084 60000001 #LYP307	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
					    	# Set held state @@@ r0.0001 @@@@ to 1 (active)
98150084 48000034 #LYP308	; WRITE r0 into r21.0084 (held state)
					    	# Move forward 13x4 bytes (0034). Skip 12 instructions to ***Next Analog***

#----------------------------------------------------------------------------------------------------------
# LY+ Release Path (Analog inactive) (6 pairs, 86+6 > 92 TOTAL)
#----------------------------------------------------------------------------------------------------------

# Check if held state @@@ 0001 @@@@ is active / If not, skip to ***Next Analog***
88150084 70000001 #LYP401	; load held-state bitmask from r21.0084 into r0 
					    	# Is held state @@@ 0001 @@@@ active? (return 0) 
41820028 60000000 #LYP402	; if inactive (1), Move forward 10x4 bytes (0028). 
					    	# Skip 9 instructions to ***Next Analog***

# Next flag as just-released button
80150008 7C006378 #LYP403	; load just-released bitmask from r21.0008 
					    	# inject button into r0 %%% 0020 %%%
90150008 60000000 #LYP404	; WRITE r0 into r21.0008 (just-released state)  

# Next clear held flag for held state @@@ 0001 @@@@
88150084 39800001 #LYP405	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
					    	# load into r12 held state @@@ 0001 @@@@
7C006078 98150084 #LYP406	; Invert r12, and write that button into r0
					    	# WRITE r0 into r21.0084 (held state)

#=========================================================================================================
# LS Y- [0070] -- PAIRS 17 -- BUTTON: UNUSED2 -- BUTTON MASK: 0040 -- HELD STATE: 0002
#=========================================================================================================

#----------------------------------------------------------------------------------------------------------
# Dynamic Button Selection (7 pairs, 92+7 > 99 TOTAL)
#----------------------------------------------------------------------------------------------------------

39800000 60000000 #LYM101 ; Clear r12 
2C0A0000 4082000C #LYM102 ; Compare Game ID (r10) to 0 (default_vertical) ;; If not 0, skip next 
39800004 60000000 #LYM103 ; Inject button mask 0004 (D-Pad Down)
2C0A0001 4082000C #LYM104 ; Compare Game ID to 1 (discs) ;; If not 1, skip next
39800001 60000000 #LYM105 ; Inject button mask 0001 (D-Pad Left) 
2C0A0002 4082000C #LYM106 ; Compare Game ID to 2 (cycle_runner) ;; If not 2, skip next 
39800020 60000000 #LYM107 ; Inject button mask 0020 (UNUSED1)

#----------------------------------------------------------------------------------------------------------
# Load Analog value and assess threshold (3 pairs, 99+3 > 102 total)
#----------------------------------------------------------------------------------------------------------

C0150070 FC000050 #LYM201	; Load LS Y (float into f0 from r21.0070)
					    	# inverse value from negative to positive (negative value now accepted and positive rejected)
C02D000C FC000800 #LYM202	; Load threshold (float into f1 from r13.000C)
					    	# Is LS Y below threshold?
41800048 60000000 #LYM203	; If yes, move forward 18x4 bytes (0048). 
					    	# Skip 17 instructions to #32.1 (LY- release)

#----------------------------------------------------------------------------------------------------------
# LY- Press Path (Analog active) (8 pairs, 102+8 > 110 TOTAL)
#----------------------------------------------------------------------------------------------------------

# Add designated button to current input 
80150000 7C006378 #LYM301	; Load button input (32-bit word into r0 from r21.0000)
						    # Set the button tag %%% 0040 %%% in r0 to 1 (active)
90150000 60000000 #LYM302	; Write r0 back into r21.0000

# Next Check held-state @@@ 0002 @@@@ / If held, skip to ***Next Analog***
88150084 70000002 #LYM303	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
						    # Is held state @@@ 0002 @@@@ active? (return 0)  
40820058 60000000 #LYM304	; if active (0), move forward 22x4 bytes (0048). 
					    	# Skip 21 instructions to ***Next Analog***

# Next flag as just-pressed button, then skip to ***Next Analog***
80150004 7C006378 #LYM305	; load just-pressed bitmask from r21.0004 into r0
					    	# inject button %%% 0040 %%% into r0 
90150004 60000000 #LYM306	; WRITE r0 into r21.0004 (just-pressed state) 

# Next flag held state @@@ 0002 @@@@, then skip to ***Next Analog***
88150084 60000002 #LYM307	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
					    	# Set held state @@@ r0.0002 @@@ to 1 (active)
98150084 48000034 #LYM308	; WRITE r0 into r21.0084 (held state)
					    	# Move forward 13x4 bytes (0034). Skip 12 instructions to ***Next Analog***

#----------------------------------------------------------------------------------------------------------
# LY- Release Path (Analog inactive) (6 pairs, 110+6 > 116 TOTAL)
#----------------------------------------------------------------------------------------------------------

# Check if held state @@@ 0002 @@@@ is active / If not, skip to ***Next Analog***
88150084 70000002 #LYM401	; load held-state bitmask from r21.0084 into r0 
					    	# Is held state @@@ 0002 @@@@ active? (return 0) 
41820028 60000000 #LYM402	; if inactive (1), Move forward 10x4 bytes (0028). 
					    	# Skip 9 instructions to *Next Analog*

# Next flag as just-released button
80150008 7C006378 #LYM403	; load just-released bitmask from r21.0008 
					    	# inject button into r0 %%% 0040 %%%
90150008 60000000 #LYM404	; WRITE r0 into r21.0008 (just-released state)  

# Next clear held flag for held state @@@ 0002 @@@@
88150084 39800002 #LYM405	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
					    	# load into r12 held state @@@ 0002 @@@@
7C006078 98150084 #LYM406	; Invert r12, and write that button into r0
				    		# WRITE r0 into r21.0084 (held state)

#==========================================================================================================
# RS X+ [0074] -- PAIRS 16 -- HELD STATE: 0040
#==========================================================================================================

#----------------------------------------------------------------------------------------------------------
# Select Output Button (1 pair, 116+1 > 117 total)
#----------------------------------------------------------------------------------------------------------

39800000 39800004 #RXP001   ; BUTTON: DPAD DOWN (RIGHT) -- BUTTON MASK: 0004

#----------------------------------------------------------------------------------------------------------
# Load Analog value and assess threshold (3 pairs, 117+3 > 120 total)
#----------------------------------------------------------------------------------------------------------

2C0A0002 40820084 #RXP100   ; Is cycle_runner? If no, skip entire section (skip 32 instructions)

C0150074 C02D000C #RXP101	; Load RS Y (float into f0 from r21.0074)
				    		# Load threshold (float into f1 from r13.000C)
FC000800 41800044 #RXP102	; Is RS Y+ below threshold?
				    		# If yes, move forward 17x4 bytes (0044). 
				    		# Skip 16 instructions to ***Release Path***

#----------------------------------------------------------------------------------------------------------
# RX+ Press Path (Analog active) (8 pairs, 120+8 > 128 TOTAL)
#----------------------------------------------------------------------------------------------------------

# Add designated button to current input 
80150000 7C006378 #RXP201	; Load button input (32-bit word into r0 from r21.0000)
				    		# Set the button tag in r0 to 1 (active)
90150000 60000000 #RXP202	; Write r0 back into r21.0000

# Next Check held-state @@@ 0004 @@@@ / If held, skip to ***Next Analog***
88150084 70000040 #RXP203	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
				    		# Is held state @@@ 0004 @@@@ active? (return 0)  
40820058 60000000 #RXP204	; if active (0), move forward 22x4 bytes (0048). 
				    		# Skip 21 instructions to ***Next Analog***

# Next flag as just-pressed button, then skip to ***Next Analog***
80150004 7C006378 #RXP205	; load just-pressed bitmask from r21.0004 into r0
				    		# inject button into r0
90150004 60000000 #RXP206	; WRITE r0 into r21.0004 (just-pressed state) 

# Next flag held state @@@ 0004 @@@@, then skip to ***Next Analog***
88150084 60000040 #RXP207	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
				    		# Set held state @@@ r0.0004 @@@@ to 1 (active)
98150084 48000034 #RXP208	; WRITE r0 into r21.0084 (held state)
				    		# Move forward 13x4 bytes (0034). Skip 12 instructions to ***Next Analog***

#----------------------------------------------------------------------------------------------------------
# RX+ Release Path (Analog inactive) (6 pairs, 128+6 > 134 TOTAL)
#----------------------------------------------------------------------------------------------------------

# Check if held state @@@ 0004 @@@@ is active / If not, skip to ***Next Analog***
88150084 70000040 #RXP301	; load held-state bitmask from r21.0084 into r0 
				    		# Is held state @@@ 0004 @@@@ active? (return 0) 
41820028 60000000 #RXP302	; if inactive (1), Move forward 10x4 bytes (0028). 
				    		# Skip 9 instructions to ***Next Analog***

# Next flag as just-released button
80150008 7C006378 #RXP303	; load just-released bitmask from r21.0008 
				    		# inject button into r0 %%% 0004 %%%
90150008 60000000 #RXP304	; WRITE r0 into r21.0008 (just-released state)  

# Next clear held flag for held state @@@ 0004 @@@@
88150084 39800040 #RXP305	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
					    	# load into r12 held state @@@ 0004 @@@@
7C006078 98150084 #RXP306	; Invert r12, and write that button into r0
					    	# WRITE r0 into r21.0084 (held state)


#==========================================================================================================
# RS X- [0074] -- PAIRS 17 -- HELD STATE: 0080
#==========================================================================================================

#----------------------------------------------------------------------------------------------------------
# Select Output Button (1 pair, 134+1 > 135 total)
#----------------------------------------------------------------------------------------------------------

39800000 39800008 #RXP001   ; BUTTON: DPAD UP (LEFT) -- BUTTON MASK: 0008

#----------------------------------------------------------------------------------------------------------
# Load Analog value and assess threshold (4 pairs, 135+4 > 139 total)
#----------------------------------------------------------------------------------------------------------

2C0A0002 4082008C #RXM101   ; Is cycle_runner? If no, skip entire section (skip 34 instructions)

C0150074 FC000050 #RXM102	; Load RS Y (float into f0 from r21.0074)
				    		# inverse value from negative to positive (negative value now accepted and positive rejected)
C02D000C FC000800 #RXM103	; Load threshold (float into f1 from r13.000C)
				    		# Is RS Y below threshold?
41800048 60000000 #RXM104	; If yes, move forward 18x4 bytes (0048). 
				    		# Skip 17 instructions to #32.1 (RX- release)

#----------------------------------------------------------------------------------------------------------
# RX- Press Path (Analog active) (8 pairs, 139+8 > 147 TOTAL)
#----------------------------------------------------------------------------------------------------------

# Add designated button to current input 
80150000 7C006378 #RXM201	; Load button input (32-bit word into r0 from r21.0000)
				    		# Set the button tag %%% 0008 %%% in r0 to 1 (active)
90150000 60000000 #RXM202	; Write r0 back into r21.0000

# Next Check held-state @@@ 0008 @@@@ / If held, skip to ***Next Analog***
88150084 70000080 #RXM203	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
				    		# Is held state @@@ 0008 @@@@ active? (return 0)  
40820058 60000000 #RXM204	; if active (0), move forward 22x4 bytes (0048). 
				    		# Skip 21 instructions to ***Next Analog***

# Next flag as just-pressed button, then skip to ***Next Analog***
80150004 7C006378 #RXM205	; load just-pressed bitmask from r21.0004 into r0
					    	# inject button %%% 0008 %%% into r0 
90150004 60000000 #RXM206	; WRITE r0 into r21.0004 (just-pressed state) 

# Next flag held state @@@ 0008 @@@@, then skip to ***Next Analog***
88150084 60000080 #RXM207	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
					    	# Set held state @@@ r0.0008 @@@ to 1 (active)
98150084 48000034 #RXM208	; WRITE r0 into r21.0084 (held state)
					    	# Move forward 13x4 bytes (0034). Skip 12 instructions to ***Next Analog***

#----------------------------------------------------------------------------------------------------------
# RX- Release Path (Analog inactive) (6 pairs, 147+6 > 153 TOTAL)
#----------------------------------------------------------------------------------------------------------

# Check if held state @@@ 0008 @@@@ is active / If not, skip to ***Next Analog***
88150084 70000080 #RXM301	; load held-state bitmask from r21.0084 into r0 
					    	# Is held state @@@ 0008 @@@@ active? (return 0) 
41820028 60000000 #RXM302	; if inactive (1), Move forward 10x4 bytes (0028). 
					    	# Skip 9 instructions to *Next Analog*

# Next flag as just-released button
80150008 7C006378 #RXM303	; load just-released bitmask from r21.0008 
				    		# inject button into r0 %%% 0008 %%%
90150008 60000000 #RXM304	; WRITE r0 into r21.0008 (just-released state)  

# Next clear held flag for held state @@@ 0008 @@@@
88150084 39800080 #RXM305	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
					    	# load into r12 held state @@@ 0008 @@@@
7C006078 98150084 #RXM306	; Invert r12, and write that button into r0
					    	# WRITE r0 into r21.0084 (held state)


#==========================================================================================================
# RS Y+ [0078] -- HELD STATE: 0010 -- PAIRS 30
#==========================================================================================================

#----------------------------------------------------------------------------------------------------------
# Select Output Button (1 pair, 153+1 > 154 total)
#----------------------------------------------------------------------------------------------------------

39800000 39800800 #RXP001   ; BUTTON: A -- BUTTON MASK: 0800

#----------------------------------------------------------------------------------------------------------
# Load Analog value and assess threshold (3 pairs, 154+3 > 157 total)
#----------------------------------------------------------------------------------------------------------

2C0A0002 40820084 #RYP101   ; Is cycle_runner? If no, skip entire section (skip 34 instructions)

C0150078 C02D000C #RYP102	; Load RS Y (float into f0 from r21.0078)
			    			# Load threshold (float into f1 from r13.000C)
FC000800 41800044 #RYP103	; Is RS Y below threshold?
			    			# If yes, move forward 17x4 bytes (0044). 
			    			# Skip 16 instructions to ***Release Path***

#----------------------------------------------------------------------------------------------------------
# RY+ Press Path (Analog active) (8 pairs, 157+8 > 165 TOTAL)
#----------------------------------------------------------------------------------------------------------

# Add designated button to current input 
80150000 7C006378 #RYP201	; Load button input (32-bit word into r0 from r21.0000)
			    			# Set the button tag %%% 0020 %%% in r0 to 1 (active)
90150000 60000000 #RYP202	; Write r0 back into r21.0000

# Next Check held-state @@@ 0001 @@@@ / If held, skip to ***Next Analog***
88150084 70000010 #RYP203	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
			    			# Is held state @@@ 0001 @@@@ active? (return 0)  
40820058 60000000 #RYP204	; if active (0), move forward 22x4 bytes (0048). 
			    			# Skip 21 instructions to ***Next Analog***

# Next flag as just-pressed button, then skip to ***Next Analog***
80150004 7C006378 #RYP205	; load just-pressed bitmask from r21.0004 into r0
			    			# inject button %%% 0020 %%% into r0
90150004 60000000 #RYP206	; WRITE r0 into r21.0004 (just-pressed state) 

# Next flag held state @@@ 0001 @@@@, then skip to ***Next Analog***
88150084 60000010 #RYP207	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
				    		# Set held state @@@ r0.0001 @@@@ to 1 (active)
98150084 48000034 #RYP208	; WRITE r0 into r21.0084 (held state)
					    	# Move forward 13x4 bytes (0034). Skip 12 instructions to ***Next Analog***

#----------------------------------------------------------------------------------------------------------
# RY+ Release Path (Analog inactive) (6 pairs, 165+6 > 171 TOTAL)
#----------------------------------------------------------------------------------------------------------

# Check if held state @@@ 0001 @@@@ is active / If not, skip to ***Next Analog***
88150084 70000010 #RYP301	; load held-state bitmask from r21.0084 into r0 
					    	# Is held state @@@ 0001 @@@@ active? (return 0) 
41820028 60000000 #RYP302	; if inactive (1), Move forward 10x4 bytes (0028). 
					    	# Skip 9 instructions to ***Next Analog***

# Next flag as just-released button
80150008 7C006378 #RYP303	; load just-released bitmask from r21.0008 
					    	# inject button into r0
90150008 60000000 #RYP304	; WRITE r0 into r21.0008 (just-released state)  

# Next clear held flag for held state @@@ 0001 @@@@
88150084 39800010 #RYP305	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
				    		# load into r12 held state @@@ 0001 @@@@
7C006078 98150084 #RYP306	; Invert r12, and write that button into r0
				    		# WRITE r0 into r21.0084 (held state)


#==========================================================================================================
# RS Y- [0078] -- PAIRS 31 -- HELD STATE: 0020
#==========================================================================================================

#----------------------------------------------------------------------------------------------------------
# Select Output Button (1 pair, 171+1 > 172 total)
#----------------------------------------------------------------------------------------------------------

39800000 39800400 #RXP001   ; BUTTON: B -- BUTTON MASK: 0400

#----------------------------------------------------------------------------------------------------------
# Load Analog value and assess threshold (4 pairs, 172+4 > 176 total)
#----------------------------------------------------------------------------------------------------------

2C0A0002 4082008C #RYM101 ; Is cycle_runner? If no, skip entire section (skip 34 instructions)

C0150078 FC000050 #RYM102	; Load RS Y (float into f0 from r21.0078)
					    	# inverse value from negative to positive (negative value now accepted and positive rejected)
C02D000C FC000800 #RYM103	; Load threshold (float into f1 from r13.000C)
					    	# Is RS Y below threshold?
41800048 60000000 #RYM104	; If yes, move forward 18x4 bytes (0048). 
					    	# Skip 17 instructions to #32.1 (RY- release)

#----------------------------------------------------------------------------------------------------------
# RY- Press Path (Analog active) (8 pairs, 176+8 > 184 TOTAL)
#----------------------------------------------------------------------------------------------------------

# Add designated button to current input 
80150000 7C006378 #RYM201	; Load button input (32-bit word into r0 from r21.0000)
					    	# Set the button tag %%% 0400 %%% in r0 to 1 (active)
90150000 60000000 #RYM202	; Write r0 back into r21.0000

# Next Check held-state @@@ 0020 @@@@ / If held, skip to ***Next Analog***
88150084 70000020 #RYM203	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
					    	# Is held state @@@ 0020 @@@@ active? (return 0)  
40820058 60000000 #RYM204	; if active (0), move forward 22x4 bytes (0048). 
					    	# Skip 21 instructions to ***Next Analog***

# Next flag as just-pressed button, then skip to ***Next Analog***
80150004 7C006378 #RYM205	; load just-pressed bitmask from r21.0004 into r0
				    		# inject button %%% 0400 %%% into r0 
90150004 60000000 #RYM206	; WRITE r0 into r21.0004 (just-pressed state) 

# Next flag held state @@@ 0020 @@@@, then skip to ***Next Analog***
88150084 60000020 #RYM207	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
					    	# Set held state @@@ r0.0020 @@@ to 1 (active)
98150084 48000034 #RYM208	; WRITE r0 into r21.0084 (held state)
				    		# Move forward 13x4 bytes (0034). Skip 12 instructions to ***Next Analog***
    
#----------------------------------------------------------------------------------------------------------
# RY- Release Path (Analog inactive) (6 pairs, 184+6 > 190 TOTAL)
#----------------------------------------------------------------------------------------------------------

# Check if held state @@@ 0002 @@@@ is active / If not, skip to ***Next Analog***
88150084 70000020 #RYM301	; load held-state bitmask from r21.0084 into r0 
					    	# Is held state @@@ 0002 @@@@ active? (return 0) 
41820028 60000000 #RYM302	; if inactive (1), Move forward 10x4 bytes (0028). 
					    	# Skip 9 instructions to *Next Analog*

# Next flag as just-released button
80150008 7C006378 #RYM303	; load just-released bitmask from r21.0008 
					    	# inject button into r0 %%% 0400 %%%
90150008 60000000 #RYM304	; WRITE r0 into r21.0008 (just-released state)  

# Next clear held flag for held state @@@ 0002 @@@@
88150084 39800020 #RYM305	; Load held-state bitmask (8 byte word into r0 from r21.0084) 
						    # load into r12 held state @@@ 0002 @@@@
7C006078 98150084 #RYM306	; Invert r12, and write that button into r0
						    # WRITE r0 into r21.0084 (held state)


#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# RETURN (2 pairs, 190+2 > 192 total)
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

4E800020 9421FFB0 #R1
60000000 00000000 #R2
						

						




##########################################################################################################
# [POINTING TO RIGHT STICK AIMING]
##########################################################################################################
# Replaces IR Pointer data with Right Stick input for Grid Tanks mode[cite: 41, 42].
# Includes a check for the pause menu to revert pointer control to the Left Stick[cite: 43].

#Pointing to Right Stick Aiming: Replace IR pointer with CC right stick (Grid Tanks + pause handling)

C23A8160 0000001C  # Hook at 0x803A8160; 28 instruction pairs implement right‑stick‑based aiming and pause‑menu behavior

88B30028 2C050002  # Read controller type/flag from the current input context ;; if it is not “2” (Classic Controller), branch to original pointer behavior
408200CC 7C0802A6  ## If not CC, skip the CC aiming logic entirely ;; otherwise, save the current link register / prepare for a small subroutine

98A3005E 3CA08000  # Write a modified or neutralized pointer byte into a status field (e.g., disable IR pointer) ;; load base address 0x80000000 to access global state
80A52FFC 2C050000  # Load the global game‑state pointer from 0x80002FFC ;; if that pointer is null, skip using it

41820008 80A50010  ## If pointer is null, branch over the dereference ;; otherwise, load the active minigame state pointer from [pointer + 0x10]
3CC5FFD9 28062CEA  # Load a game‑ID constant associated with Grid Tanks or a related mode ;; compare the current game ID against 0x2CEA (Grid Tanks identifier)

38A00000 38C00000  # Clear a working register used as a “pause/aim mode” flag ;; clear another working register used as a sub‑state or counter
40820018 38C00001  ## If the game ID does not match Grid Tanks, skip the Grid‑Tanks‑specific aiming logic ;; otherwise, set the “Grid Tanks active” flag to 1

3CA08065 80A5DBB0  # Load base address 0x80650000 and compute 0x8065DBB0 ;; read the Classic Controller input structure for this mode (right stick source)
7CA53039 4082000C  ## Test a field in that structure (e.g., pause/menu state or focus flag) ;; if not in the appropriate state, skip the special pause‑menu pointer override

C035006C 48000008  # If in the special state, load a motion/aiming float from the motion context (e.g., vertical axis) ;; otherwise, branch to use an alternate float
C0350074 C042D070  # Load another motion/aiming float (e.g., horizontal axis) ;; load a reference or scaling float from a global table at 0x8022D070

C06DC2C0 FC211824  # Load yet another float (e.g., sensitivity or deadzone) from a global at 0x802DC2C0 ;; combine these floats (e.g., scale/offset) into a final aiming value
48000035 38630004  # Branch ahead to continue with the computed aiming values ;; adjust an internal pointer/index by 4 to move to the next slot

3AB50004 2C050001  # Advance another pointer/index by 4 (e.g., next controller slot or axis) ;; compare a working register to 1 to decide which axis or state to process
4182000C C035006C  ## If the comparison matches, branch to reuse one of the motion floats (e.g., vertical) ;; otherwise, load the alternate motion float from the context

48000008 C0350074  # Branch ahead to skip the alternate load when already handled ;; or load the second motion float (e.g., horizontal) in the other path
FC200850 48000011  # Move one of the floats into a working float register for output ;; branch ahead to finalize the aiming value

3AB5FFFC 7C0803A6  # Adjust the pointer/index backward by 4 (undo temporary offset) ;; restore the link register from the saved value
4E800020 C0030020  # Return from this small aiming subroutine ;; load a float from a pointer used as the final IR/aiming output slot

EC2100B2 FC00082A  # Combine the computed aiming float with an existing value (e.g., blend CC aim with residual IR) ;; perform another float operation to refine the result
C022D06C FC000800  # Load a reference float from a global table (e.g., neutral center) ;; square the current aiming float to emphasize strong stick deflections

4180000C FC000890  ## If the squared value is above a threshold, branch to clamp or adjust it ;; otherwise, apply a different transformation to the aiming float
48000014 FC200850  # Branch ahead after clamping/adjustment ;; move the final aiming float into the output register

FC000800 41810008  # Square the aiming float again or apply a final shaping step ;; if it exceeds a secondary threshold, branch to a different clamp path
FC000890 D0030020  # Apply a final transform (e.g., sign or scale) to the aiming float ;; store the final aiming value into the IR pointer output slot

4E800020 9421FFC0  # Return from the main CC aiming hook to the caller ;; adjust the stack frame / restore registers for the surrounding function
60000000 00000000  # No‑op / alignment after the hook body ;; terminator for this C2 function




##########################################################################################################
# [BUTTON REPLACEMENT INJECTOR]
##########################################################################################################
# The code below reads Classic Controller (CC) inputs (70C4) and injects them 
# as Virtual Wiimote/Nunchuk outputs (60A5) into the game engine's memory.
# Note: Multiple inputs often map to the same output based on the game mode (State Check).

C23A6AEC 0000008C #0 --140 # Routine Start; read ? lines till the end of script

#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%2
# GAME ID ROUTING (13 pairs, 13 total)
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

90030068 7C0802A6 #1    ; Initialize Memory Registers; store input, set up Link Register

# Game ID Retrieval
3CA08000 80A52FFC #2 ; set r5 to 0x80000000 # set r5 to *(0x80002FFC) — the minigame ID pointer saved by the [MINI GAME ID] patch 
2C050000 41820008 #3 ; is the pointer null? # if null, skip the dereference (use 0 as the ID) 
80A50010 60000000 #4 ; set r5 to *(r5+0x10) — dereference to actual game mode ID; clear r10 register

# ------------------------------------------------------------------
# r10 Classification for Analog Function
#
# 0 = Default Vertical
# 1 = Light Discs
# 2 = Horizontal (Runner + Light Cycles)
# ------------------------------------------------------------------

38E00000 39000000 #5    ; initialize r7 as 0 and r10 as 0

# Light Cycle ID 1
3CC5FC27 2806A0C6 #6	; is game ID 0x03D9A0C6 (Cycle mode 1?
40820008 39000002 #7   ; if mismatch, skip instruction; set r10 to 2

# Light Cycle ID 2
3CC5FFDA 280642D1 #8	; is game ID 0x002642D1 (Cycle mode 2)?
40820008 39000002 #9   ; if mismatch, skip instruction; set r10 to 2

# Runner ID
3CC5FC37 2806C646 #10	; is game ID 0x03C9C646 (Runner)?
40820008 39000002 #11   ; if mismatch, skip instruction; set r10 to 2

# Light Discs
3CC5FFE0 28060595 #12    ; is game ID ?? (Discs)?
40820008 39000001 #13    ; if mismatch, skip instruction; set r10 to 1

#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%2
# SUBROUTINE LOOPING (10 pairs, 13+10 > 23 total, routine 2i)
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

80C30060 48000045 #1	; Loop Phase 1 Start: Fetch raw held button status from R3 offset 60
			            # Call mapping subroutine and skip next 15 instructions to Subroutine block
80830000 7CC62378 #2	; Subroutine Return Target: Fetch baseline original held button inputs from R4
			            # Combine raw inputs and baseline inputs via bitwise OR logic
90C30000 60000000 #3   ; Commit combined held inputs to memory offset 0000

80C30064 4800002D #4	; Loop Phase 2 Start: Fetch raw pressed button status from offset 64
 	                    # Call mapping subroutine and skip 10 instructions to Subroutine block
80830004 7CC62378 #5	; Subroutine Return Target: Fetch baseline original pressed button inputs from R3 offset 04
 	                    # Combine raw inputs and baseline inputs via bitwise OR logic
90C30004 60000000 #6	# Commit combined pressed inputs to memory offset 0004

80C30068 48000015 #7	; Loop Phase 3 Start: Fetch raw released button status from offset 68
			            # Call mapping subroutine and skip 5 instructions to Subroutine block
80830008 7CC62378 #8	; Subroutine Return Target: Fetch baseline original released button inputs FROM R3 offset 08
			            # Combine raw inputs and baseline inputs via bitwise OR logic
90C30008 480003A4 #9	; Commit combined released inputs to memory offset 0008 (80C30008)
			            # Unconditional Branch: Skip remaining code area to reach injection exit point (last non-nop instruction of script))
                        # --232

38A00000 60000000 #10 Register 5 value

#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%2
# UNIVERSAL BUTTON MAPPING # 6 PAIRS, TOTAL 23+6 > 29, ROUTINE 2+12 >> 14I
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%2

# Block 1: 1:1 Home
70C40800 4182000C #U1 Test input 00008 CC: Home Button; If no input, skip next instruction; 
60A58000 60000000 #U2 Add Output: Home Button

# Block 2: 1:1 Plus
70C40400 4182000C #U3 Test Input: CC Plus; If no input, skip next instruction; 
60A50010 60000000 #U4 Add Output: WM Plus

# Block 3: 1:1 Minus
70C41000 4182000C #U5 Test Input: CC Minus; Add Output: WM Minus
60A51000 60000000 #U6 End of routine split; add 1 instruction and one line

#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%2
# GAME MODE BUTTON MAPPING # 12X9 > 108 PAIRS, TOTAL 29+108 > 137, ROUTINE 14+216 >> 230I
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%2

# Block 4: CC Dpad Up
70C40001 41820044 #1 Test Input: CC D-Pad Up; If no input, skip next 16 instructions
2C080000 4082000C #2 ; Is default vertical? If no, skip next 2 instructions
60A50008 60000000 #3 ; Activate button tag 0008 D-pad Up / Move Up
2C080001 4082000C #4 ; Is discs? If no, skip next 2 instructions
60A50002 60000000 #5 ; Activate button tag 0002 D-Pad Right / Move Up
2C080002 4082000C #6 ; Is cycles? If no, skip next 2 instructions
60A50002 60000000 #7 ; Activate button tag 0002 D-Pad Right / Wheelie
2C080003 4082000C #8 ; Is runner? If no, skip next 2 instructions
60A50002 60000000 #9 ; Activate button tag 0002 D-Pad Right / Boost

# Block 5: CC Dpad Down
70C44000 41820044 #1 ; Test Input: CC D-Pad Up; If no input, skip next 16 instructions
2C080000 4082000C #2 ; Is default vertical? If no, skip next 2 instructions
60A50004 60000000 #3 ; Activate button tag 0004 D-pad Down / Move Down
2C080001 4082000C #4 ; Is discs? If no, skip next 2 instructions
60A50001 60000000 #5 ; Activate button tag 0001 D-Pad Left / Move Down
2C080002 4082000C #6 ; Is cycles? If no, skip next 2 instructions
60A50001 60000000 #7 ; Activate button tag 0001 D-Pad Left
2C080003 4082000C #8 ; Is runner? If no, skip next 2 instructions
60A50001 60000000 #9 ; Activate button tag 0001 D-Pad Left

# Block 6: CC Dpad Left
70C40002 41820044 #1 ; Test Input: CC D-Pad Up; If no input, skip next 16 instructions
2C080000 4082000C #2 ; Is default vertical? If no, skip next 2 instructions
60A50001 60000000 #3 ; Activate button tag 0001 D-Pad Left / Move Left
2C080001 4082000C #4 ; Is discs? If no, skip next 2 instructions
60A50008 60000000 #5 ; Activate button tag 0008 D-pad Up / Move Left
2C080002 4082000C #6 ; Is cycles? If no, skip next 2 instructions
60A50008 60000000 #7 ; Activate button tag 0008 D-pad Up
2C080003 4082000C #8 ; Is runner? If no, skip next 2 instructions
60A50008 60000000 #9 ; Activate button tag 0008 D-pad Up

# Block 7: CC Dpad Right
70C48000 41820044 #1 ; Test Input: CC D-Pad Up; If no input, skip next 16 instructions
2C080000 4082000C #2 ; Is default vertical? If no, skip next 2 instructions
60A50002 60000000 #3 ; Activate button tag 0002 D-Pad Right / Move Right
2C080001 4082000C #4 ; Is discs? If no, skip next 2 instructions
60A50004 60000000 #5 ; Activate button tag 0004 D-pad Down / Move Right
2C080002 4082000C #6 ; Is cycles? If no, skip next 2 instructions
60A50004 60000000 #7 ; Activate button tag 0004 D-pad Down
2C080003 4082000C #8 ; Is runner? If no, skip next 2 instructions
60A50004 60000000 #9 ; Activate button tag 0004 D-pad Down


# Block 8: CC A
70C40010 41820044 #1 ; Test Input: CC B Button; If no input, skip next 16 instructions 
2C080000 4082000C #2 ; Is default vertical? If no, skip next 2 instructions
60A50800 60000000 #3 ; Activate button tag 0800 A / Tanks: Shield; Hyperball: Catch | Backspin
2C080001 4082000C #4 ; Is discs? If no, skip next 2 instructions
60A50100 60000000 #5 ; Activate button tag 0100 2 / JUMP
2C080002 4082000C #6 ; Is cycles? If no, skip next 2 instructions
60A50080 60000000 #7 ; Activate button tag 0080 Shake / JUMP
2C080003 4082000C #8 ; Is runner? If no, skip next 2 instructions
60A50080 60000000 #9 ; Activate button tag 0080 Shake / JUMP


# Block 9: CC B
70C40040 41820044 #1 ; Test Input: CC B Button; If no input, skip next 16 instructions 
2C080000 4082000C #2 ; Is default vertical? If no, skip next 2 instructions
60A50400 60000000 #3 ; Activate button tag 0400 B / Tanks: Shoot ; Ball: Catch | Forward spin
2C080001 4082000C #4 ; Is discs? If no, skip next 2 instructions
60A50400 60000000 #3 ; Activate button tag 0400 B / Discs: Shield
2C080002 4082000C #6 ; Is cycles? If no, skip next 2 instructions
60A50200 60000000 #7 ; Activate button tag 0200 1 / Brake
2C080003 4082000C #8 ; Is runner? If no, skip next 2 instructions
60A50200 60000000 #9 ; Activate button tag 0200 1 / Brake


# Block 10: CC X
70C40008 41820044 #1 ; Test Input: CC X Button; If no input, skip next 16 instructions 
2C080000 4082000C #2 ; Is default vertical? If no, skip next 2 instructions
60A50800 60000000 #3 ; Activate button tag 0800 A / Tanks: Shield ;; Hyperball: Catch | Backspin
2C080001 4082000C #4 ; Is discs? If no, skip next 2 instructions
60A50200 60000000 #3 ; Activate button tag 0200 1 / Throw Disc
2C080002 4082000C #6 ; Is cycles? If no, skip next 2 instructions
60A50800 60000000 #7 ; Activate button tag 0800 A / Stealth 
2C080003 4082000C #8 ; Is runner? If no, skip next 2 instructions
60A50800 60000000 #9 ; Activate button tag 0800 A / Shoot


# Block 11: CC Y
70C40020 41820044 #V1 ; Test Input: CC Y Button; If no input, skip next 16 instructions 
2C080000 4082000C #2 ; Is default vertical? If no, skip next 2 instructions
60A50400 60000000 #3 ; Activate button tag 0400 B / Tanks: Shoot ; Ball: Catch | Forward spin
2C080001 4082000C #4 ; Is discs? If no, skip next 2 instructions
60A50080 60000000 #5 ; Activate button tag 0080 Shake / Powerup Attack
2C080002 4082000C #6 ; Is cycles? If no, skip next 2 instructions
60A50400 60000000 #7 ; Activate button tag 0400 B / Rearview
2C080003 4082000C #8 ; Is runner? If no, skip next 2 instructions
60A50400 60000000 #9 ; Activate button tag 0400 B / Rearview


# Block 12: CC LT
70C42000 41820044 #1 ; Test Input: CC L Trigger; If no input, skip next 16 instructions  
2C080000 4082000C #2 ; Is default vertical? If no, skip next 2 instructions
60A50800 60000000 #3 ; Activate button tag 0800 A / Tanks: Shield; Hyperball: Catch | Backspin
2C080001 4082000C #4 ; Is discs? If no, skip next 2 instructions
60A50400 60000000 #3 ; Activate button tag 0400 B / Block
2C080002 4082000C #6 ; Is cycles? If no, skip next 2 instructions
60A50001 60000000 #7 ; Activate button tag 0002 D-Pad Left / Slide
2C080003 4082000C #8 ; Is runner? If no, skip next 2 instructions
60A50001 60000000 #9 ; Activate button tag 0002 D-Pad Left / Slide


# Block 13: CC ZL
70C40080 41820044 #1 ; Test Input: CC ZL Shoulder; If no input, skip next 16 instructions 
2C080000 4082000C #2 ; Is default vertical? If no, skip next 2 instructions
60A50800 60000000 #3 ; Activate button tag 0800 A / Tanks: Shield; Hyperball: Catch | Backspin
2C080001 4082000C #4 ; Is discs? If no, skip next 2 instructions
60A50080 60000000 #5 ; Activate button tag 0080 Shake / Powerup Attack
2C080002 4082000C #6 ; Is cycles? If no, skip next 2 instructions
60A50002 60000000 #7 ; Activate button tag 0002 D-Pad Right / Wheelie
2C080003 4082000C #8 ; Is runner? If no, skip next 2 instructions
60A50400 60000000 #9 ; Activate button tag 0400 B / Boost


# Block 14: CC RT
70C40200 41820044 #1 ; Test Input: CC R Trigger; If no input, skip next 16 instructions 
2C080000 4082000C #2 ; Is default vertical? If no, skip next 2 instructions
60A50400 60000000 #3 ; Activate button tag 0400 B / Tanks: Shoot ; Ball: Catch | Forward spin
2C080001 4082000C #4 ; Is discs? If no, skip next 2 instructions
60A50100 60000000 #5 ; Activate button tag 0200 1 / Throw Disc
2C080002 4082000C #6 ; Is cycles? If no, skip next 2 instructions
60A50100 60000000 #7 ; Activate button tag 0100 2 / Accelerate
2C080003 4082000C #8 ; Is runner? If no, skip next 2 instructions
60A50100 60000000 #9 ; Activate button tag 0100 2 / Accelerate


# Block 15: CC ZR
70C40004 41820044 #1 ; Test Input: CC ZR Shoulder; If no input, skip next 16 instructions 
2C080000 4082000C #2 ; Is default vertical? If no, skip next 2 instructions
60A51000 60000000 #3 ; Activate button tag 1000 - / Tanks: Mine
2C080001 4082000C #4 ; Is discs? If no, skip next 2 instructions
60A50100 60A50200 #5 ; Activate button tags 0100 + 0200 2 + 1 / Bomb Disc
2C080002 4082000C #6 ; Is cycles? If no, skip next 2 instructions
60A50200 60000000 #7 ; Activate button tag 0200 1 / Brake
2C080003 4082000C #8 ; Is runner? If no, skip next 2 instructions
60A50200 60000000 #9 ; Activate button tag 0200 1 / Brake


####################################################################################################################
# ROUTINE END # 3 PAIRS, 137+3 > 140 TOTAL, ROUTINE 230+2 > 232
####################################################################################################################

# End of routine split
7CA62B78 4E800020 
7C0803A6 60000000

60000000 00000000
####################################################################################################################

####################################################################################################################
# BUTTON INPUT/OUTPUT CODES
####################################################################################################################

#Classic Controller input mask
#0800 | Home
#0400 | Plus
#1000 | Minus
#0001 | D-Pad Up
#4000 | D-Pad Down
#0002 | D-Pad Left
#8000 | D-Pad Right
#0010 | A
#0040 | B
#0008 | X
#0020 | Y
#2000 | L
#0200 | R
#0080 | ZL
#0004 | ZR

# Wiimote Button output masks #
#8000 | Home
#0010 | +
#1000 | -
#0001 | D-Pad Left
#0002 | D-Pad Right
#0004 | D-Pad Down
#0008 | D-Pad Up
#0800 | A
#0400 | B
#0200 | 1
#0100 | 2
#0020 | // no button
#0040 | // no button
#0080 | // no button
## Nunchuk only buttons
#2000 | Z
#4000 | C

#WM 2 + WM 1 / Discs: Bomb Throw
#WM A / Cycles: Stealth ;; Runner: Shoot ;; Tanks: Shield ; Ball: Backspin 
#WM B / Cycles: Rearview ;; Runner: Boost ;; Discs: Block ;; Tanks: Shoot ; Ball: Forward spin
#WM 1 / Cycles/Runner: Brake ;; Discs: Throw Disc 
#WM 2 / Cycles/Runner: Accelerate ;; Discs: Jump
#WM Shake / Light Disc Power up
#WM - /Tanks: Mine


[Gecko_Enabled]
$Classic Controller Support


[Gecko_Enabled]
$Classic Controller Support
